package com.bcmusic.point.service.impl;

import com.bcmusic.point.dao.UserSignInMapper;
import com.bcmusic.point.pojo.UserSignIn;
import com.bcmusic.point.service.UserSignInService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/****
 * @Author:admin
 * @Description:UserSignIn业务层接口实现类
 * @Date 2019/6/14 0:16
 *****/
@Service
public class UserSignInServiceImpl implements UserSignInService {

    @Autowired
    private UserSignInMapper userSignInMapper;


    /**
     * UserSignIn条件+分页查询
     * @param userSignIn 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public PageInfo<UserSignIn> findPage(UserSignIn userSignIn, int page, int size){
        //分页
        PageHelper.startPage(page,size);
        //搜索条件构建
        Example example = createExample(userSignIn);
        //执行搜索
        return new PageInfo<UserSignIn>(userSignInMapper.selectByExample(example));
    }

    /**
     * UserSignIn分页查询
     * @param page
     * @param size
     * @return
     */
    @Override
    public PageInfo<UserSignIn> findPage(int page, int size){
        //静态分页
        PageHelper.startPage(page,size);
        //分页查询
        return new PageInfo<UserSignIn>(userSignInMapper.selectAll());
    }

    /**
     * UserSignIn条件查询
     * @param userSignIn
     * @return
     */
    @Override
    public List<UserSignIn> findList(UserSignIn userSignIn){
        //构建查询条件
        Example example = createExample(userSignIn);
        //根据构建的条件查询数据
        return userSignInMapper.selectByExample(example);
    }


    /**
     * UserSignIn构建查询对象
     * @param userSignIn
     * @return
     */
    public Example createExample(UserSignIn userSignIn){
        Example example=new Example(UserSignIn.class);
        Example.Criteria criteria = example.createCriteria();
        if(userSignIn!=null){
            //
            if(!StringUtils.isEmpty(userSignIn.getId())){
                    criteria.andEqualTo("id",userSignIn.getId());
            }
            //
            if(!StringUtils.isEmpty(userSignIn.getUserNumber())){
                    criteria.andEqualTo("userNumber",userSignIn.getUserNumber());
            }
            //
            if(!StringUtils.isEmpty(userSignIn.getContinueDays())){
                    criteria.andEqualTo("continueDays",userSignIn.getContinueDays());
            }
            //
            if(!StringUtils.isEmpty(userSignIn.getUpdateTime())){
                    criteria.andEqualTo("updateTime",userSignIn.getUpdateTime());
            }
        }
        return example;
    }

    /**
     * 删除
     * @param id
     */
    @Override
    public void delete(Long id){
        userSignInMapper.deleteByPrimaryKey(id);
    }

    /**
     * 修改UserSignIn
     * @param userSignIn
     */
    @Override
    public void update(UserSignIn userSignIn){
        userSignInMapper.updateByPrimaryKey(userSignIn);
    }

    /**
     * 增加UserSignIn
     * @param userSignIn
     */
    @Override
    public void add(UserSignIn userSignIn){
        userSignInMapper.insert(userSignIn);
    }

    /**
     * 根据ID查询UserSignIn
     * @param id
     * @return
     */
    @Override
    public UserSignIn findById(Long id){
        return  userSignInMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询UserSignIn全部数据
     * @return
     */
    @Override
    public List<UserSignIn> findAll() {
        return userSignInMapper.selectAll();
    }

    @Override
    public void updateSelective(UserSignIn userSignIn){
        userSignInMapper.updateByPrimaryKeySelective(userSignIn);
    }
}
